#include<vector>
#include<iostream>
using namespace std;

void mergeSort(vector<int>& nums, int begin, int end, int index, vector<long long int>& order) {
	if (begin >= end - 1) 
		return;
	int mid = begin + (end - begin) / 2;
	mergeSort(nums, begin, mid, index - 1, order);
	mergeSort(nums, mid, end, index - 1, order);

	vector<int> tmp(end - begin);
	int lbegin = begin, lend = mid;
	int rbegin = mid, rend = end;
	int i = 0;
	long long int cnt = 0;
	while (lbegin < lend && rbegin < rend) {
		if (nums[lbegin] <= nums[rbegin]) {
			tmp[i++] = nums[lbegin++];
		}else{
			tmp[i++] = nums[rbegin++];
			cnt += lend - lbegin;
		}
	}
	while(lbegin<lend)
		tmp[i++] = nums[lbegin++];
	while (rbegin < rend) {
		tmp[i++] = nums[rbegin++];
	}
	for (int i = 0; i < tmp.size(); ++i)
		nums[begin+i] = tmp[i];
	order[index] += cnt;
}


//int main() {
//	int num;
//	cin >> num;
//	vector<int>nums(1 << num);
//	for ( int i = 0; i < nums.size(); ++i) {
//		cin >> nums[i];
//	}
//
//	vector<long long int>order(num + 1, 0);
//	vector<long long int>reorder(num + 1, 0);
//	vector<int>renums(nums.rbegin(), nums.rend());
//	mergeSort(nums, 0, nums.size(), num, order);
//	mergeSort(renums, 0, renums.size(), num, reorder);
//
//	cin >> num;
//	vector<int>ns(num);
//	for (int i = 0; i < ns.size(); ++i) 
//		cin >> ns[i];
//	for (int i = 0; i < ns.size(); ++i) {
//		for (int j = 1; j <= ns[i]; ++j) {
//			swap(order[j], reorder[j]);
//		}
//		long long int cnt = 0;
//		for (auto& order_ : order) {
//			cnt += order_;
//		}
//		cout << cnt << endl;
//	}
//}